home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / doc / interpreter / system.tex < prev    next >
Text File  |  1997-08-13  |  36KB  |  1,254 lines

  1. @c Copyright (C) 1996, 1997 John W. Eaton
  2. @c This is part of the Octave manual.
  3. @c For copying conditions, see the file gpl.tex.
  4.  
  5. @node System Utilities, Tips, Audio Processing, Top
  6. @chapter System Utilities
  7.  
  8. This chapter describes the functions that are available to allow you to
  9. get information about what is happening outside of Octave, while it is
  10. still running, and use this information in your program.  For example,
  11. you can get information about environment variables, the current time,
  12. and even start other programs from the Octave prompt.
  13.  
  14. @menu
  15. * Timing Utilities::            
  16. * Filesystem Utilities::        
  17. * Controlling Subprocesses::    
  18. * Process ID Information::      
  19. * Environment Variables::       
  20. * Current Working Directory::   
  21. * Password Database Functions::  
  22. * Group Database Functions::    
  23. * System Information::          
  24. @end menu
  25.  
  26. @node Timing Utilities, Filesystem Utilities, System Utilities, System Utilities
  27. @section Timing Utilities
  28.  
  29. Octave's core set of functions for manipulating time values are
  30. patterned after the corresponding functions from the standard C library.
  31. Several of these functions use a data structure for time that includes
  32. the following elements:
  33.  
  34. @table @code
  35. @item usec
  36. Microseconds after the second (0-999999).
  37.  
  38. @item sec
  39. Seconds after the minute (0-61).  This number can be 61 to account
  40. for leap seconds.
  41.  
  42. @item min
  43. Minutes after the hour (0-59).
  44.  
  45. @item hour
  46. Hours since midnight (0-23).
  47.  
  48. @item mday
  49. Day of the month (1-31).
  50.  
  51. @item mon
  52. Months since January (0-11).
  53.  
  54. @item year
  55. Years since 1900.
  56.  
  57. @item wday
  58. Days since Sunday (0-6).
  59.  
  60. @item yday
  61. Days since January 1 (0-365).
  62.  
  63. @item isdst
  64. Daylight Savings Time flag.
  65.  
  66. @item zone
  67. Time zone.
  68. @end table
  69.  
  70. @noindent
  71. In the descriptions of the following functions, this structure is
  72. referred to as a @var{tm_struct}.
  73.  
  74. @deftypefn {Loadable Function} {} time ()
  75. Return the current time as the number of seconds since the epoch.  The
  76. epoch is referenced to 00:00:00 CUT (Coordinated Universal Time) 1 Jan
  77. 1970.  For example, on Monday February 17, 1997 at 07:15:06 CUT, the
  78. value returned by @code{time} was 856163706.
  79. @end deftypefn
  80.  
  81. @deftypefn {Function File} {} ctime (@var{t})
  82. Convert a value returned from @code{time} (or any other nonnegative
  83. integer), to the local time and return a string of the same form as
  84. @code{asctime}.  The function @code{ctime (time)} is equivalent to
  85. @code{asctime (localtime (time))}.  For example,
  86.  
  87. @example
  88. @group
  89. ctime (time ())
  90.      @result{} "Mon Feb 17 01:15:06 1997"
  91. @end group
  92. @end example
  93. @end deftypefn
  94.  
  95. @deftypefn {Loadable Function} {} gmtime (@var{t})
  96. Given a value returned from time (or any nonnegative integer),
  97. return a time structure corresponding to CUT.  For example,
  98.  
  99. @example
  100. @group
  101. gmtime (time ())
  102.      @result{} @{
  103.            usec = 0
  104.            year = 97
  105.            mon = 1
  106.            mday = 17
  107.            sec = 6
  108.            zone = CST
  109.            min = 15
  110.            wday = 1
  111.            hour = 7
  112.            isdst = 0
  113.            yday = 47
  114.          @}
  115. @end group
  116. @end example
  117. @end deftypefn
  118.  
  119. @deftypefn {Loadable Function} {} localtime (@var{t})
  120. Given a value returned from time (or any nonnegative integer),
  121. return a time structure corresponding to the local time zone.
  122.  
  123. @example
  124. @group
  125. localtime (time ())
  126.      @result{} @{
  127.            usec = 0
  128.            year = 97
  129.            mon = 1
  130.            mday = 17
  131.            sec = 6
  132.            zone = CST
  133.            min = 15
  134.            wday = 1
  135.            hour = 1
  136.            isdst = 0
  137.            yday = 47
  138.          @}
  139. @end group
  140. @end example
  141. @end deftypefn
  142.  
  143. @deftypefn {Loadable Function} {} mktime (@var{tm_struct})
  144. Convert a time structure corresponding to the local time to the number
  145. of seconds since the epoch.  For example,
  146.  
  147. @example
  148. @group
  149. mktime (localtime (time ())
  150.      @result{} 856163706
  151. @end group
  152. @end example
  153. @end deftypefn
  154.  
  155. @deftypefn {Function File} {} asctime (@var{tm_struct})
  156. Convert a time structure to a string using the following five-field
  157. format: Thu Mar 28 08:40:14 1996.  For example,
  158.  
  159. @example
  160. @group
  161. asctime (localtime (time ())
  162.      @result{} "Mon Feb 17 01:15:06 1997\n"
  163. @end group
  164. @end example
  165.  
  166. This is equivalent to @code{ctime (time ())}.
  167. @end deftypefn
  168.  
  169. @deftypefn {Loadable Function} {} strftime (@var{tm_struct})
  170. Format a time structure in a flexible way using @samp{%} substitutions
  171. similar to those in @code{printf}.  Except where noted, substituted
  172. fields have a fixed size; numeric fields are padded if necessary.
  173. Padding is with zeros by default; for fields that display a single
  174. number, padding can be changed or inhibited by following the @samp{%}
  175. with one of the modifiers described below.  Unknown field specifiers are
  176. copied as normal characters.  All other characters are copied to the
  177. output without change.  For example,
  178.  
  179. @example
  180. @group
  181. strftime ("%r (%Z) %A %e %B %Y", localtime (time ())
  182.      @result{} "01:15:06 AM (CST) Monday 17 February 1997"
  183. @end group
  184. @end example
  185.  
  186. Octave's @code{strftime} function supports a superset of the ANSI C
  187. field specifiers.
  188.  
  189. @noindent
  190. Literal character fields:
  191.  
  192. @table @code
  193. @item %
  194. % character.
  195.  
  196. @item n
  197. Newline character.
  198.  
  199. @item t
  200. Tab character.
  201. @end table
  202.  
  203. @noindent
  204. Numeric modifiers (a nonstandard extension):
  205.  
  206. @table @code
  207. @item - (dash)
  208. Do not pad the field.
  209.  
  210. @item _ (underscore)
  211. Pad the field with spaces.
  212. @end table
  213.  
  214. @noindent
  215. Time fields:
  216.  
  217. @table @code
  218. @item %H
  219. Hour (00-23).
  220.  
  221. @item %I
  222. Hour (01-12).
  223.  
  224. @item %k
  225. Hour (0-23).
  226.  
  227. @item %l
  228. Hour (1-12).
  229.  
  230. @item %M
  231. Minute (00-59).
  232.  
  233. @item %p
  234. Locale's AM or PM.
  235.  
  236. @item %r
  237. Time, 12-hour (hh:mm:ss [AP]M).
  238.  
  239. @item %R
  240. Time, 24-hour (hh:mm).
  241.  
  242. @item %s
  243. Time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension).
  244.  
  245. @item %S
  246. Second (00-61).
  247.  
  248. @item %T
  249. Time, 24-hour (hh:mm:ss).
  250.  
  251. @item %X
  252. Locale's time representation (%H:%M:%S).
  253.  
  254. @item %Z
  255. Time zone (EDT), or nothing if no time zone is determinable.
  256. @end table
  257.  
  258. @noindent
  259. Date fields:
  260.  
  261. @table @code
  262. @item %a
  263. Locale's abbreviated weekday name (Sun-Sat).
  264.  
  265. @item %A
  266. Locale's full weekday name, variable length (Sunday-Saturday).
  267.  
  268. @item %b
  269. Locale's abbreviated month name (Jan-Dec).
  270.  
  271. @item %B
  272. Locale's full month name, variable length (January-December).
  273.  
  274. @item %c
  275. Locale's date and time (Sat Nov 04 12:02:33 EST 1989).
  276.  
  277. @item %C
  278. Century (00-99).
  279.  
  280. @item %d
  281. Day of month (01-31).
  282.  
  283. @item %e
  284. Day of month ( 1-31).
  285.  
  286. @item %D
  287. Date (mm/dd/yy).
  288.  
  289. @item %h
  290. Same as %b.
  291.  
  292. @item %j
  293. Day of year (001-366).
  294.  
  295. @item %m
  296. Month (01-12).
  297.  
  298. @item %U
  299. Week number of year with Sunday as first day of week (00-53).
  300.  
  301. @item %w
  302. Day of week (0-6).
  303.  
  304. @item %W
  305. Week number of year with Monday as first day of week (00-53).
  306.  
  307. @item %x
  308. Locale's date representation (mm/dd/yy).
  309.  
  310. @item %y
  311. Last two digits of year (00-99).
  312.  
  313. @item %Y
  314. Year (1970-).
  315. @end table
  316. @end deftypefn
  317.  
  318. Most of the remaining functions described in this section are not
  319. patterned after the standard C library.  Some are available for
  320. compatiblity with @sc{Matlab} and others are provided because they are
  321. useful.
  322.  
  323. @deftypefn {Function File} {} clock ()
  324. Return a vector containing the current year, month (1-12), day (1-31),
  325. hour (0-23), minute (0-59) and second (0-61).  For example,
  326.  
  327. @example
  328. @group
  329. clock ()
  330.      @result{} [ 1993, 8, 20, 4, 56, 1 ]
  331. @end group
  332. @end example
  333.  
  334. The function clock is more accurate on systems that have the
  335. @code{gettimeofday} function.
  336. @end deftypefn
  337.  
  338. @deftypefn {Function File} {} date ()
  339. Return the date as a character string in the form DD-MMM-YY.  For
  340. example,
  341.  
  342. @example
  343. @group
  344. date ()
  345.      @result{} "20-Aug-93"
  346. @end group
  347. @end example
  348. @end deftypefn
  349.  
  350. @deftypefn {Function File} {} etime (@var{t1}, @var{t2})
  351. Return the difference (in seconds) between two time values returned from
  352. @code{clock}.  For example:
  353.  
  354. @example
  355. t0 = clock ();
  356. # many computations later...
  357. elapsed_time = etime (clock (), t0);
  358. @end example
  359.  
  360. @noindent
  361. will set the variable @code{elapsed_time} to the number of seconds since
  362. the variable @code{t0} was set.
  363. @end deftypefn
  364.  
  365. @deftypefn {Built-in Function} {[@var{total}, @var{user}, @var{system}] =} cputime ();
  366. Return the CPU time used by your Octave session.  The first output is
  367. the total time spent executing your process and is equal to the sum of
  368. second and third outputs, which are the number of CPU seconds spent
  369. executing in user mode and the number of CPU seconds spent executing in
  370. system mode, respectively.  If your system does not have a way to report
  371. CPU time usage, @code{cputime} returns 0 for each of its output values.
  372. Note that because Octave used some CPU time to start, it is reasonable
  373. to check to see if @code{cputime} works by checking to see if the total
  374. CPU time used is nonzero.
  375. @end deftypefn
  376.  
  377. @deftypefn {Function File} {} is_leap_year (@var{year})
  378. Return 1 if the given year is a leap year and 0 otherwise.  If no
  379. arguments are provided, @code{is_leap_year} will use the current year.
  380. For example,
  381.  
  382. @example
  383. @group
  384. is_leap_year (2000)
  385.      @result{} 1
  386. @end group
  387. @end example
  388. @end deftypefn
  389.  
  390. @deftypefn {Function File} {} tic ()
  391. @deftypefnx {Function File} {} toc ()
  392. These functions set and check a wall-clock timer.  For example,
  393.  
  394. @example
  395. tic ();
  396. # many computations later...
  397. elapsed_time = toc ();
  398. @end example
  399.  
  400. @noindent
  401. will set the variable @code{elapsed_time} to the number of seconds since
  402. the most recent call to the function @code{tic}.
  403.  
  404. If you are more interested in the CPU time that your process used, you
  405. should use the @code{cputime} function instead.  The @code{tic} and
  406. @code{toc} functions report the actual wall clock time that elapsed
  407. between the calls.  This may include time spent processing other jobs or
  408. doing nothing at all.  For example,
  409.  
  410. @example
  411. @group
  412. tic (); sleep (5); toc ()
  413.      @result{} 5
  414. t = cputime (); sleep (5); cputime () - t
  415.      @result{} 0
  416. @end group
  417. @end example
  418.  
  419. @noindent
  420. (This example also illustrates that the CPU timer may have a fairly
  421. coarse resolution.)
  422. @end deftypefn
  423.  
  424. @deftypefn {Built-in Function} {} pause (@var{seconds})
  425. Suspend the execution of the program.  If invoked without any arguments,
  426. Octave waits until you type a character.  With a numeric argument, it
  427. pauses for the given number of seconds.  For example, the following
  428. statement prints a message and then waits 5 seconds before clearing the
  429. screen.
  430.  
  431. @example
  432. @group
  433. fprintf (stderr, "wait please...\n");
  434. pause (5);
  435. clc;
  436. @end group
  437. @end example
  438. @end deftypefn
  439.  
  440. @deftypefn {Built-in Function} {} sleep (@var{seconds})
  441. Suspend the execution of the program for the given number of seconds.
  442. @end deftypefn
  443.  
  444. @deftypefn {Built-in Function} {} usleep (@var{microseconds})
  445. Suspend the execution of the program for the given number of
  446. microseconds.  On systems where it is not possible to sleep for periods
  447. of time less than one second, @code{usleep} will pause the execution for
  448. @code{round (@var{microseconds} / 1e6)} seconds.
  449. @end deftypefn
  450.  
  451. @node Filesystem Utilities, Controlling Subprocesses, Timing Utilities, System Utilities
  452. @section Filesystem Utilities
  453.  
  454. Octave includes the following functions for renaming and deleting files,
  455. creating, deleting, and reading directories, and for getting information
  456. about the status of files.
  457.  
  458. @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})
  459. Change the name of file @var{old} to @var{new}.
  460.  
  461. If successful, @var{err} is 0 and @var{msg} is an empty string.
  462. Otherwise, @var{err} is nonzero and @var{msg} contains a
  463. system-dependent error message.
  464. @end deftypefn
  465.  
  466. @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} unlink (@var{file})
  467. Delete @var{file}.
  468.  
  469. If successful, @var{err} is 0 and @var{msg} is an empty string.
  470. Otherwise, @var{err} is nonzero and @var{msg} contains a
  471. system-dependent error message.
  472. @end deftypefn
  473.  
  474. @deftypefn {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})
  475. Return names of the files in the directory @var{dir} as an array of
  476. strings.  If an error occurs, return an empty matrix in @var{files}.
  477.  
  478. If successful, @var{err} is 0 and @var{msg} is an empty string.
  479. Otherwise, @var{err} is nonzero and @var{msg} contains a
  480. system-dependent error message.
  481. @end deftypefn
  482.  
  483. @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkdir (@var{dir})
  484. Create a directory named @var{dir}.
  485.  
  486. If successful, @var{err} is 0 and @var{msg} is an empty string.
  487. Otherwise, @var{err} is nonzero and @var{msg} contains a
  488. system-dependent error message.
  489. @end deftypefn
  490.  
  491. @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} rmdir (@var{dir})
  492. Remove the directory named @var{dir}.
  493.  
  494. If successful, @var{err} is 0 and @var{msg} is an empty string.
  495. Otherwise, @var{err} is nonzero and @var{msg} contains a
  496. system-dependent error message.
  497. @end deftypefn
  498.  
  499. @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} mkfifo (@var{name})
  500. Create a FIFO special file.
  501.  
  502. If successful, @var{err} is 0 and @var{msg} is an empty string.
  503. Otherwise, @var{err} is nonzero and @var{msg} contains a
  504. system-dependent error message.
  505. @end deftypefn
  506.  
  507. @c XXX FIXME XXX -- this needs to be explained, but I don't feel up to
  508. @c it just now...
  509.  
  510. @deftypefn {Built-in Function} {} umask (@var{mask})
  511. Set the permission mask for file creation.  The parameter @var{mask} is
  512. interpreted as an octal number.
  513. @end deftypefn
  514.  
  515. @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} stat (@var{file})
  516. @deftypefnx {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})
  517. Return a structure @var{s} containing the following information about
  518. @var{file}.
  519.  
  520. @table @code
  521. @item dev
  522. ID of device containing a directory entry for this file.
  523.  
  524. @item ino
  525. File number of the file.
  526.  
  527. @item modestr
  528. File mode, as a string of ten letters or dashes as would be returned by
  529. @kbd{ls -l}.
  530.  
  531. @item nlink
  532. Number of links.
  533.  
  534. @item uid
  535. User ID of file's owner.
  536.  
  537. @item gid
  538. Group ID of file's group.
  539.  
  540. @item rdev
  541. ID of device for block or character special files.
  542.  
  543. @item size
  544. Size in bytes.
  545.  
  546. @item atime
  547. Time of last access in the same form as time values returned from
  548. @code{time}.  @xref{Timing Utilities}.
  549.  
  550. @item mtime
  551. Time of last modification in the same form as time values returned from
  552. @code{time}.  @xref{Timing Utilities}.
  553.  
  554. @item ctime
  555. Time of last file status change in the same form as time values returned from
  556. @code{time}.  @xref{Timing Utilities}.
  557.  
  558. @item blksize
  559. Size of blocks in the file.
  560.  
  561. @item blocks
  562. Number of blocks allocated for file.
  563. @end table
  564.  
  565. If the call is successful @var{err} is 0 and @var{msg} is an empty
  566. string.  If the file does not exist, or some other error occurs, @var{s}
  567. is an empty matrix, @var{err} is @minus{}1, and @var{msg} contains the
  568. corresponding system error message.
  569.  
  570. If @var{file} is a symbolic link, @code{stat} will return information
  571. about the actual file the is referenced by the link.  Use @code{lstat}
  572. if you want information about the symbolic link itself.
  573.  
  574. For example,
  575.  
  576. @example
  577. @group
  578. [s, err, msg] = stat ("/vmlinuz")
  579.      @result{} s =
  580.         @{
  581.           atime = 855399756
  582.           rdev = 0
  583.           ctime = 847219094
  584.           uid = 0
  585.           size = 389218
  586.           blksize = 4096
  587.           mtime = 847219094
  588.           gid = 6
  589.           nlink = 1
  590.           blocks = 768
  591.           modestr = -rw-r--r--
  592.           ino = 9316
  593.           dev = 2049
  594.         @}
  595.      @result{} err = 0
  596.      @result{} msg = 
  597. @end group
  598. @end example
  599. @end deftypefn
  600.  
  601. @deftypefn {Built-in Function} {} glob (@var{pattern})
  602. Given an array of strings in @var{pattern}, return the list of file
  603. names that any of them, or an empty string if no patterns match.  Tilde
  604. expansion is performed on each of the patterns before looking for
  605. matching file names.  For example,
  606.  
  607. @example
  608. @group
  609. glob ("/vm*")
  610.      @result{} "/vmlinuz"
  611. @end group
  612. @end example
  613.  
  614. Note that multiple values are returned in a string matrix with the fill
  615. character set to ASCII NUL.
  616. @end deftypefn
  617.  
  618. @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})
  619. Return 1 or zero for each element of @var{string} that matches any of
  620. the elements of the string array @var{pattern}, using the rules of
  621. filename pattern matching.  For example,
  622.  
  623. @example
  624. @group
  625. fnmatch ("a*b", ["ab"; "axyzb"; "xyzab"])
  626.      @result{} [ 1; 1; 0 ]
  627. @end group
  628. @end example
  629. @end deftypefn
  630.  
  631. @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})
  632. Return the absolute name name of @var{file} if it can be found in
  633. @var{path}.  The value of @var{path} should be a colon-separated list of
  634. directories in the format described for the built-in variable
  635. @code{LOADPATH}.
  636.  
  637. If the file cannot be found in the path, an empty matrix is returned.
  638. For example,
  639.  
  640. @example
  641. file_in_path (LOADPATH, "nargchk.m")
  642.      @result{} "@value{OCTAVEHOME}/share/octave/2.0/m/general/nargchk.m"
  643. @end example
  644. @end deftypefn
  645.  
  646. @deftypefn {Built-in Function} {} tilde_expand (@var{string})
  647. Performs tilde expansion on @var{string}.  If @var{string} begins with a
  648. tilde character, (@samp{~}), all of the characters preceding the first
  649. slash (or all characters, if there is no slash) are treated as a
  650. possible user name, and the tilde and the following characters up to the
  651. slash are replaced by the home directory of the named user.  If the
  652. tilde is followed immediately by a slash, the tilde is replaced by the
  653. home directory of the user running Octave.  For example,
  654.  
  655. @example
  656. @group
  657. tilde_expand ("~joeuser/bin")
  658.      @result{} "/home/joeuser/bin"
  659. tilde_expand ("~/bin")
  660.      @result{} "/home/jwe/bin"
  661. @end group
  662. @end example
  663. @end deftypefn
  664.  
  665. @node Controlling Subprocesses, Process ID Information, Filesystem Utilities, System Utilities
  666. @section Controlling Subprocesses
  667.  
  668. Octave includes some high-level commands like @code{system} and
  669. @code{popen} for starting subprocesses.  If you want to run another
  670. program to perform some task and then look at its output, you will
  671. probably want to use these functions.
  672.  
  673. Octave also provides several very low-level Unix-like functions which
  674. can also be used for starting subprocesses, but you should probably only
  675. use them if you can't find any way to do what you need with the
  676. higher-level functions.
  677.  
  678. @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})
  679. Execute a shell command specified by @var{string}.  The second argument is optional.
  680. If @var{type} is @code{"async"}, the process is started in the
  681. background and the process id of the child process is returned
  682. immediately.  Otherwise, the process is started, and Octave waits until
  683. it exits.  If @var{type} argument is omitted, a value of @code{"sync"}
  684. is assumed.
  685.  
  686. If two input arguments are given (the actual value of
  687. @var{return_output} is irrelevant) and the subprocess is started
  688. synchronously, or if @var{system} is called with one input argument and
  689. one or more output arguments, the output from the command is returned.
  690. Otherwise, if the subprocess is executed synchronously, it's output is
  691. sent to the standard output.  To send the output of a command executed
  692. with @var{system} through the pager, use a command like
  693.  
  694. @example
  695. disp (system (cmd, 1));
  696. @end example
  697.  
  698. @noindent
  699. or
  700.  
  701. @example
  702. printf ("%s\n", system (cmd, 1));
  703. @end example
  704.  
  705. The @code{system} function can return two values.  The first is any
  706. output from the command that was written to the standard output stream,
  707. and the second is the output status of the command.  For example,
  708.  
  709. @example
  710. [output, status] = system ("echo foo; exit 2");
  711. @end example
  712.  
  713. @noindent
  714. will set the variable @code{output} to the string @samp{foo}, and the
  715. variable @code{status} to the integer @samp{2}.
  716. @end deftypefn
  717.  
  718. @deftypefn {Built-in Function} {fid =} popen (@var{command}, @var{mode})
  719. Start a process and create a pipe.  The name of the command to run is
  720. given by @var{command}.  The file identifier corresponding to the input
  721. or output stream of the process is returned in @var{fid}.  The argument
  722. @var{mode} may be
  723.  
  724. @table @code
  725. @item "r"
  726. The pipe will be connected to the standard output of the process, and
  727. open for reading.
  728.  
  729. @item "w"
  730. The pipe will be connected to the standard input of the process, and
  731. open for writing.
  732. @end table
  733.  
  734. For example,
  735.  
  736. @example
  737. @group
  738. fid = popen ("ls -ltr / | tail -3", "r");
  739. while (isstr (s = fgets (fid)))
  740.   fputs (stdout, s);
  741. endwhile
  742.      @print{} drwxr-xr-x  33 root  root  3072 Feb 15 13:28 etc
  743.      @print{} drwxr-xr-x   3 root  root  1024 Feb 15 13:28 lib
  744.      @print{} drwxrwxrwt  15 root  root  2048 Feb 17 14:53 tmp
  745. @end group
  746. @end example
  747. @end deftypefn
  748.  
  749. @deftypefn {Built-in Function} {} pclose (@var{fid})
  750. Close a file identifier that was opened by @code{popen}.  You may also
  751. use @code{fclose} for the same purpose.
  752. @end deftypefn
  753.  
  754. @deftypefn {Built-in Function} {[@var{in}, @var{out}, @var{pid}] =} popen2 (@var{command}, @var{args})
  755. Start a subprocess with two-way communication.  The name of the process
  756. is given by @var{command}, and @var{args} is an array of strings
  757. containing options for the command.  The file identifiers for the input
  758. and output streams of the subprocess are returned in @var{in} and
  759. @var{out}.  If execution of the command is successful, @var{pid}
  760. contains the process ID of the subprocess.  Otherwise, @var{pid} is
  761. @minus{}1.
  762.  
  763. For example,
  764.  
  765. @example
  766. @group
  767. [in, out, pid] = popen2 ("sort", "-nr");
  768. fputs (in, "these\nare\nsome\nstrings\n");
  769. fclose (in);
  770. while (isstr (s = fgets (out)))
  771.   fputs (stdout, s);
  772. endwhile
  773. fclose (out);
  774.      @print{} are
  775.      @print{} some
  776.      @print{} strings
  777.      @print{} these
  778. @end group
  779. @end example
  780. @end deftypefn
  781.  
  782. @defvr {Built-in Variable} EXEC_PATH
  783. The variable @code{EXEC_PATH} is a colon separated list of directories
  784. to search when executing subprograms.  Its initial value is taken from
  785. the environment variable @code{OCTAVE_EXEC_PATH} (if it exists) or
  786. @code{PATH}, but that value can be overridden by the the command line
  787. argument @code{--exec-path PATH}, or by setting the value of
  788. @code{EXEC_PATH} in a startup script.  If the value of @code{EXEC_PATH}
  789. begins (ends) with a colon, the directories
  790.  
  791. @example
  792. @group
  793. @var{octave-home}/libexec/octave/site/exec/@var{arch}
  794. @var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}
  795. @end group
  796. @end example
  797.  
  798. @noindent
  799. are prepended (appended) to @code{EXEC_PATH}, where @var{octave-home}
  800. is the top-level directory where all of Octave is installed
  801. (the default value is @file{@value{OCTAVEHOME}}).  If you don't specify
  802. a value for @code{EXEC_PATH} explicitly, these special directories are
  803. prepended to your shell path.
  804. @end defvr
  805.  
  806. In most cases, the following functions simply decode their arguments and
  807. make the corresponding Unix system calls.  For a complete example of how
  808. they can be used, look at the definition of the function @code{popen2}.
  809.  
  810. @deftypefn {Built-in Function} {[@var{pid}, @var{msg}] =} fork ()
  811. Create a copy of the current process.
  812.  
  813. Fork can return one of the following values:
  814.  
  815. @table @asis
  816. @item > 0
  817. You are in the parent process.  The value returned from @code{fork} is
  818. the process id of the child process.  You should probably arrange to
  819. wait for any child processes to exit.
  820.  
  821. @item 0
  822. You are in the child process.  You can call @code{exec} to start another
  823. process.  If that fails, you should probably call @code{exit}.
  824.  
  825. @item < 0
  826. The call to @code{fork} failed for some reason.  You must take evasive
  827. action.  A system dependent error message will be waiting in @var{msg}.
  828. @end table
  829. @end deftypefn
  830.  
  831. @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} exec (@var{file}, @var{args})
  832. Replace current process with a new process.  Calling @code{exec} without
  833. first calling @code{fork} will terminate your current Octave process and
  834. replace it with the program named by @var{file}.  For example,
  835.  
  836. @example
  837. exec ("ls" "-l")
  838. @end example
  839.  
  840. @noindent
  841. will run @code{ls} and return you to your shell prompt.
  842.  
  843. If successful, @code{exec} does not return.  If @code{exec} does return,
  844. @var{err} will be nonzero, and @var{msg} will contain a system-dependent
  845. error message.
  846. @end deftypefn
  847.  
  848. @deftypefn {Built-in Function} {[@var{file_ids}, @var{err}, @var{msg}] =} pipe ()
  849. Create a pipe and return the vector @var{file_ids}, which corresponding
  850. to the reading and writing ends of the pipe.
  851.  
  852. If successful, @var{err} is 0 and @var{msg} is an empty string.
  853. Otherwise, @var{err} is nonzero and @var{msg} contains a
  854. system-dependent error message.
  855. @end deftypefn
  856.  
  857. @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} dup2 (@var{old}, @var{new})
  858. Duplicate a file descriptor.
  859.  
  860. If successful, @var{fid} is greater than zero and contains the new file
  861. ID.  Otherwise, @var{fid} is negative and @var{msg} contains a
  862. system-dependent error message.
  863. @end deftypefn
  864.  
  865. @deftypefn {Built-in Function} {[@var{pid}, @var{msg}] =} waitpid (@var{pid}, @var{options})
  866. Wait for process @var{pid} to terminate.  The @var{pid} argument can be:
  867.  
  868. @table @asis
  869. @item @minus{}1
  870. Wait for any child process.
  871.  
  872. @item 0
  873. Wait for any child process whose process group ID is equal to that of
  874. the Octave interpreter process.
  875.  
  876. @item > 0
  877. Wait for termination of the child process with ID @var{pid}.
  878. @end table
  879.  
  880. The @var{options} argument can be:
  881.  
  882. @table @asis
  883. @item 0
  884. Wait until signal is received or a child process exits (this is the
  885. default if the @var{options} argument is missing).
  886.  
  887. @item 1
  888. Do not hang if status is not immediately available.
  889.  
  890. @item 2
  891. Report the status of any child processes that are stopped, and whose
  892. status has not yet been reported since they stopped.
  893.  
  894. @item 3
  895. Implies both 1 and 2.
  896. @end table
  897.  
  898. If the returned value of @var{pid} is greater than 0, it is the process
  899. ID of the child process that exited.  If an error occurs, @var{pid} will
  900. be less than zero and @var{msg} will contain a system-dependent error
  901. message.
  902. @end deftypefn
  903.  
  904. @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})
  905. Change the properties of the open file @var{fid}.  The following values
  906. may be passed as @var{request}:
  907.  
  908. @vtable @code
  909. @item F_DUPFD
  910. Return a duplicate file descriptor.
  911.  
  912. @item F_GETFD
  913. Return the file descriptor flags for @var{fid}.
  914.  
  915. @item F_SETFD
  916. Set the file descriptor flags for @var{fid}.
  917.  
  918. @item F_GETFL
  919. Return the file status flags for @var{fid}.  The following codes may be
  920. returned (some of the flags may be undefined on some systems).
  921.  
  922. @vtable @code
  923. @item O_RDONLY
  924. Open for reading only.
  925.  
  926. @item O_WRONLY
  927. Open for writing only.
  928.  
  929. @item O_RDWR
  930. Open for reading and writing.
  931.  
  932. @item O_APPEND
  933. Append on each write.
  934.  
  935. @item O_NONBLOCK
  936. Nonblocking mode.
  937.  
  938. @item O_SYNC
  939. Wait for writes to complete.
  940.  
  941. @item O_ASYNC
  942. Asynchronous I/O.
  943. @end vtable
  944.  
  945. @item F_SETFL
  946. Set the file status flags for @var{fid} to the value specified by
  947. @var{arg}.  The only flags that can be changed are @code{O_APPEND} and
  948. @code{O_NONBLOCK}.
  949. @end vtable
  950.  
  951. If successful, @var{err} is 0 and @var{msg} is an empty string.
  952. Otherwise, @var{err} is nonzero and @var{msg} contains a
  953. system-dependent error message.
  954. @end deftypefn
  955.  
  956. @node Process ID Information, Environment Variables, Controlling Subprocesses, System Utilities
  957. @section Process, Group, and User IDs
  958.  
  959. @deftypefn {Built-in Function} {} getpgrp ()
  960. Return the process group id of the current process.
  961. @end deftypefn
  962.  
  963. @deftypefn {Built-in Function} {} getpid ()
  964. Return the process id of the current process.
  965. @end deftypefn
  966.  
  967. @deftypefn {Built-in Function} {} getppid ()
  968. Return the process id of the parent process.
  969. @end deftypefn
  970.  
  971. @deftypefn {Built-in Function} {} geteuid ()
  972. Return the effective user id of the current process.
  973. @end deftypefn
  974.  
  975. @deftypefn {Built-in Function} {} getuid ()
  976. Return the real user id of the current process.
  977. @end deftypefn
  978.  
  979. @deftypefn {Built-in Function} {} getegid ()
  980. Return the effective group id of the current process.
  981. @end deftypefn
  982.  
  983. @deftypefn {Built-in Function} {} getgid ()
  984. Return the real group id of the current process.
  985. @end deftypefn
  986.  
  987. @node Environment Variables, Current Working Directory, Process ID Information, System Utilities
  988. @section Environment Variables
  989.  
  990. @deftypefn {Built-in Function} {} getenv (@var{var})
  991. Return the value of the environment variable @var{var}.  For example,
  992.  
  993. @example
  994. getenv ("PATH")
  995. @end example
  996.  
  997. @noindent
  998. returns a string containing the value of your path.
  999. @end deftypefn
  1000.  
  1001. @deftypefn {Built-in Function} {} putenv (@var{var}, @var{value})
  1002. Set the value of the environment variable @var{var} to @var{value}.
  1003. @end deftypefn
  1004.  
  1005. @node Current Working Directory, Password Database Functions, Environment Variables, System Utilities
  1006. @section Current Working Directory
  1007.  
  1008. @deffn {Command} cd dir
  1009. @deffnx {Command} chdir dir
  1010. Change the current working directory to @var{dir}.  For example,
  1011.  
  1012. @example
  1013. cd ~/octave
  1014. @end example
  1015.  
  1016. @noindent
  1017. Changes the current working directory to @file{~/octave}.  If the
  1018. directory does not exist, an error message is printed and the working
  1019. directory is not changed.
  1020. @end deffn
  1021.  
  1022. @deftypefn {Built-in Function} {} pwd ()
  1023. Return the current working directory.
  1024. @end deftypefn
  1025.  
  1026. @defvr {Built-in Variable} PWD
  1027. The current working directory.  The value of @code{PWD} is updated each
  1028. time the current working directory is changed with the @samp{cd}
  1029. command.
  1030. @end defvr
  1031.  
  1032. @deffn {Command} ls options
  1033. @deffnx {Command} dir options
  1034. List directory contents.  For example,
  1035.  
  1036. @example
  1037. ls -l
  1038.      @print{} total 12
  1039.      @print{} -rw-r--r--   1 jwe  users  4488 Aug 19 04:02 foo.m
  1040.      @print{} -rw-r--r--   1 jwe  users  1315 Aug 17 23:14 bar.m
  1041. @end example
  1042.  
  1043. The @code{dir} and @code{ls} commands are implemented by calling your
  1044. system's directory listing command, so the available options may vary
  1045. from system to system.
  1046. @end deffn
  1047.  
  1048. @node Password Database Functions, Group Database Functions, Current Working Directory, System Utilities
  1049. @section Password Database Functions
  1050.  
  1051. Octave's password database functions return information in a structure
  1052. with the following fields.
  1053.  
  1054. @table @code
  1055. @item name
  1056. The user name.
  1057.  
  1058. @item passwd
  1059. The encrypted password, if available.
  1060.  
  1061. @item uid
  1062. The numeric user id.
  1063.  
  1064. @item gid
  1065. The numeric group id.
  1066.  
  1067. @item gecos
  1068. The GECOS field.
  1069.  
  1070. @item dir
  1071. The home directory.
  1072.  
  1073. @item shell
  1074. The initial shell.
  1075. @end table
  1076.  
  1077. In the descriptions of the following functions, this data structure is
  1078. referred to as a @var{pw_struct}.
  1079.  
  1080. @deftypefn {Loadable Function} {@var{pw_struct} = } getpwent ()
  1081. Return a structure containing an entry from the password database,
  1082. opening it if necessary. Once the end of the data has been reached,
  1083. @code{getpwent} returns 0.
  1084. @end deftypefn
  1085.  
  1086. @deftypefn {Loadable Function} {@var{pw_struct} = } getpwuid (@var{uid}).
  1087. Return a structure containing the first entry from the password database
  1088. with the user ID @var{uid}.  If the user ID does not exist in the
  1089. database, @code{getpwuid} returns 0.
  1090. @end deftypefn
  1091.  
  1092. @deftypefn {Loadable Function} {@var{pw_struct} = } getpwnam (@var{name})
  1093. Return a structure containing the first entry from the password database
  1094. with the user name @var{name}.  If the user name does not exist in the
  1095. database, @code{getpwname} returns 0.
  1096. @end deftypefn
  1097.  
  1098. @deftypefn {Loadable Function} {} setpwent ()
  1099. Return the internal pointer to the beginning of the password database.
  1100. @end deftypefn
  1101.  
  1102. @deftypefn {Loadable Function} {} endpwent ()
  1103. Close the password database.
  1104. @end deftypefn
  1105.  
  1106. @node Group Database Functions, System Information, Password Database Functions, System Utilities
  1107. @section Group Database Functions
  1108.  
  1109. Octave's group database functions return information in a structure
  1110. with the following fields.
  1111.  
  1112. @table @code
  1113. @item name
  1114. The user name.
  1115.  
  1116. @item passwd
  1117. The encrypted password, if available.
  1118.  
  1119. @item gid
  1120. The numeric group id.
  1121.  
  1122. @item mem
  1123. The members of the group.
  1124. @end table
  1125.  
  1126. In the descriptions of the following functions, this data structure is
  1127. referred to as a @var{grp_struct}.
  1128.  
  1129. @deftypefn {Loadable Function} {@var{grp_struct} =} getgrent ()
  1130. Return an entry from the group database, opening it if necessary.
  1131. Once the end of the data has been reached, @code{getgrent} returns 0.
  1132. @end deftypefn
  1133.  
  1134. @deftypefn {Loadable Function} {@var{grp_struct} =} getgrgid (@var{gid}).
  1135. Return the first entry from the group database with the group ID
  1136. @var{gid}.  If the group ID does not exist in the database,
  1137. @code{getgrgid} returns 0.
  1138. @end deftypefn
  1139.  
  1140. @deftypefn {Loadable Function} {@var{grp_struct} =} getgrnam (@var{name})
  1141. Return the first entry from the group database with the group name
  1142. @var{name}.  If the group name does not exist in the database,
  1143. @code{getgrname} returns 0.
  1144. @end deftypefn
  1145.  
  1146. @deftypefn {Loadable Function} {} setgrent ()
  1147. Return the internal pointer to the beginning of the group database.
  1148. @end deftypefn
  1149.  
  1150. @deftypefn {Loadable Function} {} endgrent ()
  1151. Close the group database.
  1152. @end deftypefn
  1153.  
  1154. @node System Information,  , Group Database Functions, System Utilities
  1155. @section System Information
  1156.  
  1157. @deftypefn {Built-in Function} {} computer ()
  1158. Print or return a string of the form @var{cpu}-@var{vendor}-@var{os}
  1159. that identifies the kind of computer Octave is running on.  If invoked
  1160. with an output argument, the value is returned instead of printed.  For
  1161. example,
  1162.  
  1163. @example
  1164. @group
  1165. computer ()
  1166.      @print{} i586-pc-linux-gnu
  1167.  
  1168. x = computer ()
  1169.      @result{} x = "i586-pc-linux-gnu"
  1170. @end group
  1171. @end example
  1172. @end deftypefn
  1173.  
  1174. @deftypefn {Built-in Function} {} isieee ()
  1175. Return 1 if your computer claims to conform to the IEEE standard for
  1176. floating point calculations.
  1177. @end deftypefn
  1178.  
  1179. @deftypefn {Built-in Function} {} version ()
  1180. Return Octave's version number as a string.  This is also the value of
  1181. the built-in variable @code{OCTAVE_VERSION}.
  1182. @end deftypefn
  1183.  
  1184. @defvr {Built-in Variable} OCTAVE_VERSION
  1185. The version number of Octave, as a string.
  1186. @end defvr
  1187.  
  1188. @deftypefn {Built-in Function} {} octave_config_info ()
  1189. Return a structure containing configuration and installation
  1190. information.
  1191. @end deftypefn
  1192.  
  1193. @deftypefn {Loadable Function} {} getrusage ()
  1194. Return a structure containing a number of statistics about the current
  1195. Octave process.  Not all fields are available on all systems.  If it is
  1196. not possible to get CPU time statistics, the CPU time slots are set to
  1197. zero.  Other missing data are replaced by NaN.  Here is a list of all
  1198. the possible fields that can be present in the structure returned by
  1199. @code{getrusage}:
  1200.  
  1201. @table @code
  1202. @item 
  1203. @item idrss
  1204. Unshared data size.
  1205.  
  1206. @item inblock
  1207. Number of block input operations.
  1208.  
  1209. @item isrss
  1210. Unshared stack size.
  1211.  
  1212. @item ixrss
  1213. Shared memory size.
  1214.  
  1215. @item majflt
  1216. Number of major page faults.
  1217.  
  1218. @item maxrss
  1219. Maximum data size.
  1220.  
  1221. @item minflt
  1222. Number of minor page faults.
  1223.  
  1224. @item msgrcv
  1225. Number of messages received.
  1226.  
  1227. @item msgsnd
  1228. Number of messages sent.
  1229.  
  1230. @item nivcsw
  1231. Number of involuntary context switches.
  1232.  
  1233. @item nsignals
  1234. Number of signals received.
  1235.  
  1236. @item nswap
  1237. Number of swaps.
  1238.  
  1239. @item nvcsw
  1240. Number of voluntary context switches.
  1241.  
  1242. @item oublock
  1243. Number of block output operations.
  1244.  
  1245. @item stime
  1246. A structure containing the system CPU time used.  The structure has the
  1247. elements @code{sec} (seconds) @code{usec} (microseconds).
  1248.  
  1249. @item utime
  1250. A structure containing the user CPU time used.  The structure has the
  1251. elements @code{sec} (seconds) @code{usec} (microseconds).
  1252. @end table
  1253. @end deftypefn
  1254.